<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>物联网</title>
		<style>
      *{
        margin: 10;
        padding: 0;
        box-sizing: border-box;
        font-family: "Courier New", 楷体;
      }
      body{
        display: flex;
        flex-direction: column;
        background-image: linear-gradient(200deg,#ec77ab,#7873f5);;
        background-repeat: no-repeat;
        background-attachment: fixed;
        align-items: center;
        justify-content: center;
      }
      .menu{
        width: 400px;
        height: 48px;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        list-style-type: none;
        /* background-color: #8746ff; */
        line-height: 48px;
      }
      .menu a {
        width: 70px;
        display: block;
        font-size: 24px;
        color: white;
        text-decoration: none;
        text-align: center;
      }
      .menu a:hover {
        background-color: #af64a0;
      }
      .page {
        display: inline;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        height: 400px;
        width: 400px;
        line-height: 50px;
        font-size: 20px;
        letter-spacing: 3px;
        color: white;
        padding-left: 11px;
        padding-top: 25px;
        /* background-color: #ec77ab; */
		  }
      span {
        /* background-color: aqua; */
        height: 40px;
        width: 400px;
        font-size: 20px;
        text-align: center;
      }
      button {
        background-color: #b700ff;
        color: #ffffff;
        box-shadow: 2px 5px 15px rgba(0, 0, 0, 0.7);
        border-radius: 10px;
        height: 40px;
        width: 100px;
        font-size: 20px;
        border: none;
      }
      button:active {
        background-color: #6a0094;
      }
		</style>
  </head>
  <body>
    <div>
      <ul class="menu">
        <li><a href="/index.html">首页</a></li>
        <li><a href="/config.html">配置</a></li>
        <li><a href="/connect.html">网络</a></li>
        <li><a href="/public.html">发布</a></li>
        <li><a href="/subcribe.html">订阅</a></li>
      </ul>
    </div>
    <div class="page">
      WiFi设备IP：<span id="deviceIP">NA</span><br>
      WiFi连接状态：<span id="wifiStatus">NA</span><br>
      MQTT连接状态：<span id="mqttStatus">NA</span><br>
      系统时钟(ms)：<span id="systemTick">NA</span><br>
      重连是否成功：<span id="recRet">NA</span><br>
      <button type="button" onclick="public()">一键重连</button>
    </div>
    <script>
      function connect() {
        var xhttp = new XMLHttpRequest();
        xhttp.open("GET", "/connect", true);
        xhttp.send();
      }
      setInterval(function() {
        connect_info();
      }, 500);
      function connect_info() {
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
          if (this.readyState == 4 && this.status == 200) {
            let array = this.responseText.split(',');
            document.getElementById("deviceIP").innerHTML = array[0];
            document.getElementById("wifiStatus").innerHTML = array[1];
            document.getElementById("mqttStatus").innerHTML = array[2];
            document.getElementById("systemTick").innerHTML = array[3];
          }
        };
				xhttp.open("GET", "/infomation", true);
				xhttp.send();
      }
    </script>
</body>
</html>